var adList;
var localData =[
    {"id": 1,"adName": "shaofancun","adCLassName":"shaofanchun","state":1},
    {"id": 2,"adName": "asfas","adCLassName":"shaofanchun","state":1},
    {"id": 3,"adName": "bbbb","adCLassName":"shaofanchun","state":0},
    {"id": 4,"adName": "www","adCLassName":"shaofanchun","state":0}
    ];
$(function () {
    if($("#adList").length>0){
        adList = $.fn.bsgrid.init('adList', {
            localData: localData,   //本地json
            //url:'',               //数据地址
            // autoLoad: false,
            pageSizeSelect: true,
            pageSize: 10,
            stripeRows: true
        });
    }
    
});
var ad={
    //表格操作
    operate:function(record, rowIndex, colIndex, options) {
        var id=adList.getRecordIndexValue(record, 'id')
        var operate='';
        operate+='<a href="adEdit.html?id=' + id + '">编辑</a> <a href="javascript:;" onclick="ad.del(' + id + ')">删除</a>';
        return operate;
    },
    state:function(record, rowIndex, colIndex, options){
        var state=adList.getRecordIndexValue(record, 'state');
        if(state==1) return '<span class="sui-text-success">有效</span>';
        else if(state==0) return '<span class="sui-text-disabled">无效</span>'
    },
    del:function(id){
        table.del({
            "id":id,
            "url":'../../testApi/dels.php'
        })
    }
}

$("#adAdd").validate({
	rules:{
		adName:{required:true},
        adClassId:{required:true}
	}
})
$("#adEdit").validate({
	rules:{
		adName:{required:true},
        adClassId:{required:true}
	}
})
$(document).on('change','.fileImg',function(e){
    $(this).uploadimg(this,e);
})